package com.power.sifa.approve.model.pojo.vo;

import cn.hutool.core.collection.CollectionUtil;
import com.power.sifa.approve.model.Aprv_process_materials;
import com.power.sifa.approve.model.enumeration.Tp_procmaterialEnum;
import com.power.sifa.approve.model.enumeration.Tp_stageEnum;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @ClassName DocumentTreeVO
 * @Author xiongzw
 * @Date 2023/9/26 16:42
 * @Description
 * @Version: 1.0
 **/

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class DocumentTreeVO {

    /**
     * value
     */
    private String key;
    /**
     * 名称
     */
    private String title;

    /**
     * 层级
     */
    private Integer level;

    /**
     * 是否已经送达
     */
    private Boolean isSend = Boolean.FALSE;

    /**
     * 文件
     */
    private Aprv_process_materials document;
    /**
     * 子文件
     */
    private List<DocumentTreeVO> children;

    /**
     * 获取初始化的树形结构
     * @return
     */
    public static DocumentTreeVO getDefaultDocumentList() {
        List<DocumentTreeVO> children_level1 = new ArrayList<>();
        Arrays.stream(Tp_stageEnum.values()).forEach(item -> {
            Tp_stageEnum stageEnum = Tp_stageEnum.getById(item.getId());
            List<Tp_procmaterialEnum> procmaterialList = Tp_procmaterialEnum.getByStage(stageEnum);
            List<DocumentTreeVO> children_level2 = new ArrayList<>();
            if (CollectionUtil.isNotEmpty(procmaterialList)) {
                procmaterialList.stream().forEach(procmaterial -> {
                    children_level2.add(DocumentTreeVO.builder().key(procmaterial.getId().toString()).title(procmaterial.getDesc()).level(2).document(null).children(null)
                            .build());
                });
            }
            children_level1.add(DocumentTreeVO.builder().key(stageEnum.getKey()).title(stageEnum.getName()).level(1).document(null).children(children_level2)
                    .build());
        });
        //
        List<DocumentTreeVO> children_level2 = new ArrayList<>();
        children_level2.add(DocumentTreeVO.builder().key(Tp_procmaterialEnum.MATER_CUSTOMER.getId().toString()).title(Tp_procmaterialEnum.MATER_CUSTOMER.getDesc()).level(2).document(null).children(null)
                .build());

        List<DocumentTreeVO> children_level3 = new ArrayList<>();
        children_level3.add(DocumentTreeVO.builder().key(Tp_procmaterialEnum.SUPERVISE_TELL.getId().toString()).title(Tp_procmaterialEnum.SUPERVISE_TELL.getDesc()).level(2).document(null).children(null)
                .build());

        children_level3.add(DocumentTreeVO.builder().key(Tp_procmaterialEnum.SUPERVISE_NOTICE.getId().toString()).title(Tp_procmaterialEnum.SUPERVISE_NOTICE.getDesc()).level(2).document(null).children(null)
                .build());

        children_level3.add(DocumentTreeVO.builder().key(Tp_procmaterialEnum.SUPERVISE_RESULT.getId().toString()).title(Tp_procmaterialEnum.SUPERVISE_RESULT.getDesc()).level(2).document(null).children(null)
                .build());


        children_level1.add(DocumentTreeVO.builder().key("customer").title("自定义材料").level(1).document(null).children(children_level2)
                .build());
        children_level1.add(DocumentTreeVO.builder().key("supervise").title("复议监督材料").level(1).document(null).children(children_level3)
                .build());

        DocumentTreeVO root = DocumentTreeVO.builder().key("root").title("全部").level(0).document(null).children(children_level1)
                .build();
        return root;
    }
}
